$('#btn-new').linkbutton({
    onClick: function () {
        opts.action = 'new';
        opts.row = undefined;
        url = opts.createUrl;
        BX.goto(url);
    }
});
$('#btn-edit').linkbutton({
    onClick: function () {
        opts.row = $('#dg-listview').datagrid('getSelected');
        if (opts.row) {
            opts.action = 'edit';
            url = opts.saveUrl;
            url = url.addParam({id: opts.row[opts.pk]});
            BX.goto(url);
        } else {
            $.messager.alert('提示', '请选择要修改的行。', 'alert');
        }
    }
});
$('#btn-view').linkbutton({
    onClick: function () {
        opts.row = $('#dg-listview').datagrid('getSelected');
        if (opts.row) {
            opts.action = 'view';
            url = opts.viewUrl;
            url = url.addParam({id: opts.row[opts.pk]});
            BX.goto(url);
        } else {
            $.messager.alert('提示', '请选择要查看的行。', 'warning');
        }
    }
});
$('#btn-delete').linkbutton({
    onClick: function () {
        var row = $('#dg-listview').datagrid('getSelected');
        if (row) {
            $.messager.confirm('确认', '确定要删除吗？', function (r) {
                if (r) {
                    var url = opts.deleteUrl.addParam({id: row[opts.pk]});
                    $.post(url, {}, function (data) {
                        if (data.type == 'error') {
                            $.messager.alert('执行结果', data.message, 'error');
                        } else {
                            $.messager.alert('执行结果', data.message, 'info');
                            $('#dg-listview').datagrid('reload');
                        }
                    });
                }
            });
        }
    }
});
// search
$('#btn-search').linkbutton({
    onClick: function () {
        $('#dg-listview').datagrid('reload');
    }
});
$('#btn-clear').linkbutton({
    onClick: function () {
        $('#search-form').form('reset');
    }
});